#include "PlayerStateMoving.h"
#include "Player.h"


PlayerStateMoving::PlayerStateMoving(Player* player) : 
PlayerState(player){}

PlayerStateMoving::~PlayerStateMoving(void){}

void PlayerStateMoving::activate()
{
	_player->getAnimationMgr().setAnimation("walk");
}

void PlayerStateMoving::deactivate()
{

}

int PlayerStateMoving::update()
{
	if (_player->damageReceived())
		return PSRV_TAKE_DAMAGE;
	_player->applyVelocity();
	if (_player->getControlState()->isKeyPressed(CControls::Key(CTRL_JUMP, 0), 0))
	{
		_player->_jumpStartPosition = _player->_position.y;
		return PSRV_JUMPING;
	}
	else if (_player->getControlState()->isKeyPressed(CControls::Key(CTRL_SHOOT, 0), 0))
	{
		return PSRV_ATTACK;
	}
	else if (_player->getControlState()->isKeyPressed(CControls::Key(CTRL_DASH, 0), 0))
	{
		return PSRV_DASH;
	}
	else if (_player->getMovementStateX() == MSX_NONE)
		return PSRV_IDLE;
	else if (!_player->_onGround)
		return PSRV_FALLING;
	
	return PSRV_NOTHING;
}
